package com.nkzy.bigeventback.controller;

import com.nkzy.bigeventback.entity.Article;
import com.nkzy.bigeventback.entity.PageBean;
import com.nkzy.bigeventback.entity.Result;
import com.nkzy.bigeventback.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService as;

    //新增文章
    @PostMapping
    public Result addArticle(@RequestBody Article article){
        as.addArticle(article);
        System.out.println("----"+article+"---");
        return Result.success();
    }
    @GetMapping
    /*
    参数说明：
    pageNum:页号
    pageSize：每页文章个数
    categoryId：文章所在分类id
    state：文章状态
    */
    public Result findArticle(int pageNum,
                              int pageSize,
                              @RequestParam(required = false) Integer categoryId,
                              @RequestParam(required = false) String state){
        PageBean pb =as.findArticle(pageNum,pageSize,categoryId,state);
        return Result.success(pb);
    }
}
